package com.example.analysis.service.impl;

import com.example.analysis.entity.Class;
import com.example.analysis.entity.Course;
import com.example.analysis.utils.Response;
import com.example.analysis.mapper.ClassDao;
import com.example.analysis.service.ClassService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class ClassServiceImpl implements ClassService {
    @Resource
    private ClassDao classDao;


    @Override
    public Response<Class> insert(Class aClass) {
        try {
            classDao.insert(aClass);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Class> getById(String classId) {
        Class aClass = classDao.selectByPrimaryKey(classId);
        if (aClass != null) {
            return new Response<>(true, "Success", aClass);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<Class> getByName(String className) {
        Class aClass = classDao.selectByName(className);
        if (aClass != null) {
            return new Response<>(true, "Success", aClass);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<List<Class>> getAll() {
        List<Class> classList = classDao.getAll();

        if (!classList.isEmpty()) {
            return new Response<>(true, "Success", classList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
